import React, { PureComponent, PropTypes } from 'react';
import { autobind } from 'core-decorators';
import { Select } from 'antd';

const Option = Select.Option;

export default class SelectProduct extends PureComponent {
  static propTypes = {
    list: PropTypes.array.isRequired,
    handleChange: PropTypes.func,
  }

  static defaultProps = {
  	handleChange: () => { },
  }

  @autobind
  handleChange(value) {
  	this.props.handleChange(value);
  }

  render() {
  	const { list, defaultValue } = this.props;
    if (list.length === 0) {
      return null;
    }
  	return (
    <Select defaultValue={defaultValue || list[0].portfolioName} style={{ width: 120 }} onChange={this.handleChange}>
      {
        	list.map(item => <Option value={item.portfolioCode} key={item.portfolioCode}>{item.portfolioName}</Option>)
        }
    </Select>
  	);
  }
}
